//
//  SACollectionViewController.m
//  SunOn
//
//  Created by RazeenCheng on 2017/5/2.
//  Copyright © 2017年 NeoZhang. All rights reserved.
//  信息收集界面   根据角色不同显示不同界面信息   普通销售:我反馈的信息  部门:最新信息

#import "SACollectionViewController.h"
#import "SACollectionViewLayout.h"//信息收集界面的layout
#import "SALittleModuleCollectionViewCell.h"//小模块cell
#import "SAMoreHeadCollectionViewCell.h"//更多头视图
#import "SASalesCollectionTableViewCell.h"//销售人员cell
#import "SADepartmentCollectionTableViewCell.h"//部门人员cell
#import "SAInformationFeedbackViewController.h"//信息反馈界面
#import "SAAllFeedbackViewController.h"//我反馈信息所有界面
#import "SACollectionMessageDetaileViewController.h"//信息详情界面
#import "SACollectionNoticeViewController.h"//消息通知界面
@interface SACollectionViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UICollectionView *MaincollectionView;

@property (nonatomic, strong) UITableView *messageTabview;

@end

@implementation SACollectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self configureView];
    [self configureCollectionView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - view cycle
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    UIButton *messageInformation = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [messageInformation setBackgroundImage:SAImageNamed(@"NaviBar-xiaoxi1") forState:(UIControlStateNormal)];
    messageInformation.frame = CGRectMake(0, 0, 25, 25);
    [messageInformation addTarget:self action:@selector(moreMessageInformation:) forControlEvents:(UIControlEventTouchUpInside)];
    UIBarButtonItem *rightitem = [[UIBarButtonItem alloc] initWithCustomView:messageInformation];
    self.navigationItem.rightBarButtonItem = rightitem;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#0d88e8"]}];
}

#pragma mark - custom method
//更多消息
- (void)moreMessageInformation:(UIButton *)sender {
    [sender setBackgroundImage:SAImageNamed(@"NaviBar-xiaoxi2") forState:(UIControlStateNormal)];
    SACollectionNoticeViewController *MessageDetaileVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SACollectionNoticeViewController"];
    [self.navigationController pushViewController:MessageDetaileVC animated:YES];
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 8;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
        UIImageView *imageview = [[UIImageView alloc] initWithImage:SAImageNamed(@"组159副本3")];
        imageview.frame = CGRectMake(0, 0, SASCREEN_WIDTH, 125);
        [cell.contentView addSubview:imageview];
        return cell;
    }else if (indexPath.row < 6) {
        SALittleModuleCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SALittleModuleCollectionViewCell" forIndexPath:indexPath];
        switch (indexPath.row) {
            case 1:
                [cell configureCellWithTitle:@"产品信息" ImgName:@"xinxishouji-chanpinxinxi"];
                break;
            case 2:
                [cell configureCellWithTitle:@"同业信息" ImgName:@"xinxishouji-tongyexinxi"];
                break;
            case 3:
                [cell configureCellWithTitle:@"客户信息" ImgName:@"xinxishouji-kehuxinxi"];
                break;
            case 4:
                [cell configureCellWithTitle:@"市场热点" ImgName:@"xinxishouji-shichangredian"];
                break;
            default:
                [cell configureCellWithTitle:@"其他信息" ImgName:@"xinxishouji-qitaxinxi"];
                break;
        }
        cell.backgroundColor = [UIColor whiteColor];
        return cell;
    }else if (indexPath.row == 6) {
        SAMoreHeadCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SAMoreHeadCollectionViewCell" forIndexPath:indexPath];
        cell.title.text = @"我反馈的信息";
        cell.moreLB.text = @"查看全部";
        cell.backgroundColor = [UIColor whiteColor];
        return cell;
    }else {
        UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"tabview" forIndexPath:indexPath];
        self.messageTabview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SASCREEN_WIDTH, cell.contentView.height) style:(UITableViewStylePlain)];
        [self.messageTabview registerNib:[UINib nibWithNibName:@"SASalesCollectionTableViewCell" bundle:nil] forCellReuseIdentifier:@"SASalesCollectionTableViewCell"];
        [self.messageTabview registerNib:[UINib nibWithNibName:@"SADepartmentCollectionTableViewCell" bundle:nil] forCellReuseIdentifier:@"SADepartmentCollectionTableViewCell"];
        self.messageTabview.delegate = self;
        self.messageTabview.dataSource = self;
        self.messageTabview.showsVerticalScrollIndicator = NO;
        self.messageTabview.showsHorizontalScrollIndicator = NO;
        [cell.contentView addSubview:self.messageTabview];
        return cell;
    }
}
#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        //顶视图
    }else {
        if (indexPath.row == 6) {
            SAAllFeedbackViewController *allfeedVC = [[SAAllFeedbackViewController alloc] init];
            allfeedVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:allfeedVC animated:YES];
        }else {
            SAInformationFeedbackViewController *informationVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SAInformationFeedbackViewController"];
            switch (indexPath.row) {
                case 1:
                {
                    //产品信息
                    informationVC.str = @"产品信息";
                }
                    break;
                case 2:
                {
                    //同业信息
                    informationVC.str = @"同业信息";
                }
                    break;
                case 3:
                {
                    //客户信息
                    informationVC.str = @"客户信息";
                }
                    break;
                case 4:
                {
                    //市场热点
                    informationVC.str = @"市场热点";
                }
                    break;
                case 5:
                {
                    //其他信息
                    informationVC.str = @"其他信息";
                }
                    break;
                default:
                    break;
            }
            [self.navigationController pushViewController:informationVC animated:YES];
        }
    }
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SASalesCollectionTableViewCell *sasleCell = [tableView dequeueReusableCellWithIdentifier:@"SASalesCollectionTableViewCell" forIndexPath:indexPath];
    sasleCell.selectionStyle = UITableViewCellSelectionStyleNone;
    return sasleCell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 89 + 150 * SAkHeight_scale + 9 + 44 + 10;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    SACollectionMessageDetaileViewController *MessageDetaileVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SACollectionMessageDetaileViewController"];
    [self.navigationController pushViewController:MessageDetaileVC animated:YES];
}
#pragma mark - view layout
//配置viewcontroller
- (void)configureView {
    self.title = @"圣奥研发中心";
    self.navigationController.title = @"信息收集";
}

//配置collectonview
- (void)configureCollectionView {
    SACollectionViewLayout *layout = [[SACollectionViewLayout alloc] init];
    self.MaincollectionView.dataSource = self;
    self.MaincollectionView.delegate = self;
    self.MaincollectionView.scrollEnabled = NO;
    [self.MaincollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    [self.MaincollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"tabview"];
    [self.MaincollectionView registerNib:[UINib nibWithNibName:@"SALittleModuleCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"SALittleModuleCollectionViewCell"];
    [self.MaincollectionView registerNib:[UINib nibWithNibName:@"SAMoreHeadCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"SAMoreHeadCollectionViewCell"];
    [self.MaincollectionView setCollectionViewLayout:layout];
    self.MaincollectionView.backgroundColor = [UIColor clearColor];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
